import logging
from redis import StrictRedis


class Config(object):
    """项目的配置"""
    DEBUG = True

    SECRET_KEY = "Jsc2VTlKuemr8ehV9/CYFmNmYr4VHuVfNoOVHH6s+0KW7Z6o1EdZ8/SiAu3Tw+jw"
    # 为数据库添加配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 再请求结束时候，SQLALCHEMY会主动执行db.session.commit()
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    # 为redis添加配置
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379
    # Session保存位置
    SESSION_TYPE = "redis"
    # 开启Session签名
    SESSION_USE_SIGNER = True
    # 指定Session保存的redis
    SESSION_REDIS = StrictRedis(host=REDIS_HOST,port=REDIS_PORT)
    # 设置需要时间
    SESSION_PERMANENT = False
    # 设置过期时间
    PERMANENT_SESSION_LIFTTIME = 86400 * 2
    # 默认日志等级
    LOG_LEVEL = logging.DEBUG


class DevelopmentConfig(Config):
    """开发模式下的设置"""
    DEBUG = True


class ProductionConfig(Config):
    """生产模式下的配置"""
    DEBUG = False
    LOG_LEVEL = logging.ERROR


class TestingConfig(Config):
    """测试模式下的配置"""
    DEBUG = True
    TESTING = True

# 定义配置字典
config = {
    "development":DevelopmentConfig,
    "production":ProductionConfig,
    "testing":TestingConfig
}

